package controllers;

import java.util.Date;
import java.util.List;

import models.DriverJourney;
import models.HitchhikerJourney;
import models.Journey;
import models.User;
import models.Vehicle;
import play.modules.paginate.ValuePaginator;
import play.mvc.With;

import common.FBSecure;

@With(FBSecure.class)
public class EditDriverJourney extends FBController {

	public static void editdriverjourneydetails(long id){
		
		setFbIdandName();

		User user = getUser();
		
		DriverJourney driverJourney = DriverJourney.findById(id);
		
		render(user, driverJourney);
	}
	
	public static void updatedriverjourneydetails(long id, String departurestate,
			String departuretownn, String departurestreet, Date departuredate,
			String departurehour, String arrivestate,
			String arrivetownn, String arrivestreet, String journeynotes,
			String expecteddistance, String expectedtime, boolean priceshare,
			Integer numberofhitchhiker){
		setFbIdandName();

		User user = getUser();
		
		DriverJourney driverJourney = DriverJourney.findById(id);
		
		driverJourney.updateDriver(departurestate, departuretownn, departurestreet, departuredate,
				departurehour, arrivestate, arrivetownn, arrivestreet, journeynotes, 
				expecteddistance, expectedtime, priceshare, numberofhitchhiker);
		
		renderTemplate("DriverJourneyDetails/driverjourneydetails.html", user, driverJourney);
	}
	
	public static void deletedriverjourney(long id){
		
		setFbIdandName();

		User user = getUser();
		
		DriverJourney journey = DriverJourney.findById(id);
				
		journey.delete();
		
		User profileUser = getUser();
		
		List<Journey> journeyList = profileUser.getJourneyList();
		
		ValuePaginator paginator = new ValuePaginator(journeyList);
		paginator.setPageSize(5);
		
		renderTemplate("Profile/profile.html", user, profileUser, journeyList, paginator);
		
	}
	
}
